home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / LIBRARY / TOT / DEMO.EXE / arc / DEMIO24.PAS < prev    next >
Pascal/Delphi Source File  |  1991-02-10  |  2KB  |  93 lines

  1. program DemoIOTwentyFour;
  2. {demIO24 - Leave Fields hooks}
  3.  
  4. {Using a leave field hook to validate input and not allowing
  5.  the user to leave the active field until the value is correct.}
  6.  
  7. Uses DOS, CRT,
  8.      totFAST, totREAL, totINPUT, totIO1, totIO2, totIO3, 
  9.      totSTR, totDATE, totMSG;
  10. var
  11.   Field1, Field2: IntIOOBJ;
  12.   Keys: ControlKeysIOOBJ;
  13.   Manager: FormOBJ;
  14.  
  15. {$F+}
  16. function LeaveFieldTrap(var ID:word):tAction;
  17. {}
  18. var 
  19.    Action:tAction;
  20.    HelpTxt:  MessageOBJ;
  21. begin
  22.    Action := None;
  23.    if ((ID = 1) and (Field1.IsNull=false) and (Odd(Field1.GetValue)))
  24.    or ((ID = 2) and (Field2.IsNull=false) and (not Odd(Field2.GetValue))) 
  25.    then
  26.    begin
  27.       with HelpTxt do
  28.       begin
  29.          Init(1,' Error ');
  30.          AddLine('');
  31.          if ID = 1 then
  32.             Addline(' You must enter an EVEN number ')
  33.          else 
  34.             Addline(' You must enter an ODD number ');
  35.          AddLine('');
  36.          Show;
  37.          Done;
  38.       end;
  39.       ID := StayPut;
  40.       Action := Refresh;
  41.    end;
  42.    LeaveFieldTrap := Action;
  43. end; {EnterFieldTrap}
  44. {$F-}
  45.  
  46.  
  47. procedure InitVars;
  48. {}
  49. begin
  50.    with Field1 do
  51.    begin
  52.       Init(40,4,5);
  53.       SetLabel('Enter an EVEN number');
  54.       SetID(1);
  55.    end;
  56.    with Field2 do
  57.    begin
  58.       Init(40,6,5);
  59.       SetLabel('Enter an  ODD number');
  60.       SetID(2);
  61.    end;
  62.    Keys.Init;
  63. end; {InitVars}
  64.  
  65. procedure DisposeVars;
  66. {}
  67. begin
  68.    Field1.Done;
  69.    Field2.Done;
  70.    Keys.Done;
  71. end; {DisposeVars}
  72.  
  73. begin
  74.    InitVars;
  75.    ClrScr;
  76.    Screen.FillBox(10,2,70,10,79,1);
  77.    Screen.WriteCenter(9,79,' Press Tab to change fields. F10 to finish. ');
  78.    with Manager do
  79.    begin
  80.       Init;
  81.       AddItem(Keys);
  82.       AddItem(Field1);
  83.       AddItem(Field2);
  84.       SetLeaveHook(LeaveFieldTrap);
  85.       if Go <> Finished then
  86.       begin
  87.          GotoXY(1,20);
  88.          writeln('You escaped!');
  89.       end;
  90.       DisposeVars;
  91.       Done;
  92.    end;
  93. end.